package main

import (
	"github.com/gin-gonic/gin"
	"log"
)

type User struct {
	Id  string `form:"id"`
	Age int    `form:"age" binding:"required"`
}

func main() {
	engine := gin.Default()

	engine.POST("/hello", func(ctx *gin.Context) {
		var user User
		ctx.ShouldBind(&user)
		ctx.JSON(200, user)
	})

	engine.GET("/hello/:id", func(ctx *gin.Context) {

		ctx.JSON(200, gin.H{
			"message": ctx.Param("id"),
		})

	})

	engine.GET("/user/*path", func(ctx *gin.Context) {

		ctx.JSON(200, gin.H{
			"message": ctx.Param("path"),
		})
	})

	v1 := engine.Group("/v1")
	v1.GET("/find", func(ctx *gin.Context) {
		ctx.JSON(200, gin.H{"message": "v1 find"})
	})

	v2 := engine.Group("/v2")
	v2.GET("/find", func(ctx *gin.Context) {
		ctx.JSON(200, gin.H{"message": "v2 find"})
	})

	err := engine.Run(":8080")
	if err != nil {
		log.Fatal(err)
	}

}
